package server;

import java.util.ArrayList;
import java.util.List;

public class Mapper {

    List<MappedHost> hosts = new ArrayList<>();//一个service持有多个host
    String port = "8080";//默认端口8080

    public String getPort() {
        return port;
    }

    public void addHost(MappedHost host) {
        this.hosts.add(host);
    }

    public List<MappedHost> getHosts() {
        return hosts;
    }

    public void setPort(String port) {
        this.port = port;
    }

    protected abstract static class MapElement<T> {

        public final String name;
        public final T object;

        public MapElement(String name, T object) {
            this.name = name;
            this.object = object;
        }

        public String getName() {
            return name;
        }

        public T getObject() {
            return object;
        }
    }

    protected static final class MappedHost extends MapElement<Host>{

        private List<MappedContext> contexts = new ArrayList();

        public void addContext(MappedContext mappedContext){
            this.contexts.add(mappedContext);
        }

        public List<MappedContext> getContexts() {
            return contexts;
        }

        public MappedHost(String name, Host object) {
            super(name, object);
        }
    }

    protected static final class MappedContext extends MapElement<Context>{

        private List<MappedWrapper> wrappers = new ArrayList<>();

        public void addMappedWrapper(MappedWrapper mappedWrapper){
            this.wrappers.add(mappedWrapper);
        }

        public List<MappedWrapper> getWrappers() {
            return wrappers;
        }

        public MappedContext(String name, Context object) {
            super(name, object);
        }
    }

    protected static final class MappedWrapper extends MapElement<Wrapper>{

        public MappedWrapper(String name, Wrapper object) {
            super(name, object);
        }
    }
}
